<?php


class Category_mdl extends CI_Model
{
	
	
	const TBL_CATEGORY = 'tb_category';
	
	public function __construct()
	{		
		parent::__construct();
	}
	
	public function get_category_by_id( $id,$leve=1 )
	{
		if( $id ){
			$this->db->where( 'parentid',$id );
		}
		$category = $this->db->select( 'id,name,parentid,rank' )
							->from( self::TBL_CATEGORY )
							->get()
							->result_array();
		return $category;
	}
	
	/**
	 * 
	 * 添加分类
	 * @param array $data
	 */
	public function add_category( $data )
	{
		return $this->db->insert( self::TBL_CATEGORY,$data );
	}
	
	/**
	 * 
	 * 删除
	 * @param int $id
	 */
	public function del( $id )
	{
		$this->db->where( 'id', $id );
		$this->db->delete( self::TBL_CATEGORY ); 
	}
	
	/**
	 * 
	 * 根据ID取得分类信息
	 * @param unknown_type $id
	 */
	public function get_one_by_id($id)
	{
		$category = array();
		$category = $this->db->where( 'id', $id )->get(self::TBL_CATEGORY)->row_array();
		return $category;
							
	}
	
	/**
	 * 
	 * 更新分类
	 * @param array $data
	 * @param array $config
	 */
	public function update( $data,$config)
	{
		$this->db->where($config);
		
		return $this->db->update(self::TBL_CATEGORY, $data); 
	}
	
	
}